package com.kfm.base.io.b;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class Demo05 {

    public static void main(String[] args) {
        try(FileInputStream fis = new FileInputStream("d:/io/buffered-input.txt");
            BufferedInputStream bis = new BufferedInputStream(fis);){

            /*
                读取所有内容，当内容是 m 时做标记.
                最后回到标记点，再读一次
             */
            int read;
            while ((read = bis.read()) != -1){
                char c = (char) read;
                if (c == 'm'){
                    bis.mark(1);
                }
//                System.out.println(c);
            }
            System.out.println(bis.available());

            // 重置
            bis.reset();

            System.out.println(bis.available());
            while ((read = bis.read()) != -1){
                char c = (char) read;
                System.out.println(c);
            }

        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
